<?php
require('../../../wp-load.php');
$html = "";
if($_POST["tipo"] == "subcategoria"){
	$curr_cat = get_category_by_slug( $_POST["category"] );
	$the_query = new WP_Query(array('cat'=>$curr_cat->term_id));
	while ( $the_query->have_posts() ) :
			$the_query->the_post();	
			$post_categories = wp_get_post_categories($the_query->post->ID);
			$cats = array();
			$url = "";
			if ( get_post_meta($the_query->post->ID, 'url') ) $url = get_post_meta($the_query->post->ID, 'url',true);

			foreach($post_categories as $c) {
					$cat = get_category($c); if($cat->cat_ID != $curr_cat) $cats[] = $cat->slug;
			}

			$html .= "<div class='span4 item'>";
					$html .= "<div class='img-experto'>";
							$html .= "<a href='".get_permalink()."' title=''>".get_the_post_thumbnail()."</a>";
					$html .= "</div>";
					$html .= "<div class='titulo-portafolio'><a href='".get_permalink()."'>". get_the_title() ."</a></div>";
					$html .= "<div class='extracto-portafolio'>". get_the_excerpt() ."</div>";
					$html .= "<div class='extracto-portafolio'>". $url ."</div>";

			$html .= "</div>";
	endwhile; 
}else{
	$curr_cat = get_category_by_slug( $_POST["category"] );
	$the_query = new WP_Query(array('cat'=>$curr_cat->term_id));
	while ( $the_query->have_posts() ) :
			$the_query->the_post();	
			$post_categories = wp_get_post_categories($the_query->post->ID);
			$cats = array();
			$url = "";
			if ( get_post_meta($the_query->post->ID, 'url') ) $url = get_post_meta($the_query->post->ID, 'url',true);

			foreach($post_categories as $c) {
					$cat = get_category($c); if($cat->cat_ID != $curr_cat) $cats[] = $cat->slug;
			}

			$html .= "<div class='span4 item'>";
					$html .= "<div class='img-experto'>";
							$html .= "<a href='".get_permalink()."' title=''>".get_the_post_thumbnail()."</a>";
					$html .= "</div>";
					$html .= "<div class='titulo-portafolio'><a href='".get_permalink()."'>". get_the_title() ."</a></div>";
					$html .= "<div class='extracto-portafolio'>". get_the_excerpt() ."</div>";
					$html .= "<div class='extracto-portafolio'>". $url ."</div>";

			$html .= "</div>";
	endwhile; 
}

echo $html;
?>